package com.cssl.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cssl.pojo.Booklevel;
import com.cssl.service.BooklevelService;
import com.cssl.vo.BooklevelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class BooklevelController {

    @Autowired
    private BooklevelService bservice;


    /**
     * 查询
     * @param current
     * @param size
     * @return
     */
    @PostMapping("/pagebooklevels")
    public BooklevelVo pagebooklevels(Integer current,Integer size){
         if (current==null||current<1){
             current=1;
         }
         if(size==null||size<1){
             size=3;
         }
         BooklevelVo booklevleVo = new BooklevelVo();
         IPage<Booklevel> page = new Page<>(current,size);
        /* IPage<Booklevel> page1= bservice.page(page);
         IPage<Booklevel> ipage = new Page<>(current, size);*/
         bservice.page(page, null);
         booklevleVo.setCurrent(current);
         booklevleVo.setSize(size);
         booklevleVo.setTotal(page.getTotal());
         booklevleVo.setUserList(page.getRecords());
         booklevleVo.setCount(page.getPages());

         return booklevleVo;
    }

    /**
     * 添加
     */
    @PostMapping("/addbookjibie")
    public boolean Addbookjibie(Booklevel bll){
        return bservice.save(bll);
    }

    /**
     * 通过id找到对象
     */
    @PostMapping("/selid")
    public Booklevel selid(Integer bid){
        return bservice.getBaseMapper().selectById(bid);
    }

    @PostMapping("/updid")
    public boolean updid(Booklevel bl){
        return bservice.updateById(bl);
    }

    @PostMapping("/delid")
    public int delid(Integer bid){
        return  bservice.getBaseMapper().deleteById(bid);
    }

    @PostMapping("/selbname")
    public Booklevel selbname(int bid){
        return bservice.selbname(bid);
    }

    @PostMapping("/booklevelall")
    public List<Booklevel> booklevelall(){
       return bservice.list();
    }
}
